<?php

namespace App\Traits;

trait ApiResponseTrait
{
    protected function success($data = [], $message = '', $code = 0)
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data
        ]);
    }

    protected function error($message = '操作失败', $code = 400, $data = [])
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data
        ]);
    }
}
